package com.woniu.controller;

import com.woniu.pojo.*;
import com.woniu.service.ClazzService;
import com.woniu.service.PermissionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.beans.IntrospectionException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;
    @Resource
    private ClazzService clazzService;

    /**
     * 跳转到就业展示页面图
     * @return
     */
    @RequestMapping("salplatu")
    public String salplatu(){
        return "permission/salplatu";
    }
    /**
     * 跳转到角色权限区
     * @return
     */
    @RequestMapping("enterpermission")
    public String enterpermission(){
        return "role/changepermission";
    }

    /**
     * 跳转到就业展示页面标
     * @return
     */
    @RequestMapping("salplabiao")
    public String salplabiao(){
        return "permission/salplabiao";
    }

    /**
     * 跳转到男女比例图像展示页面
     * @return
     */
    @RequestMapping("rate")
    public String rate(){
        return "permission/rate";
    }

    /**
     * 跳转到所有班级折现展示页面
     * @return
     */

    @RequestMapping("lineju")
    public String line(){
        return "permission/lineju";
    }
    /**
     * 跳转到所有班级折现展示页面(准备)
     * @return
     */
    @RequestMapping("selectstuAll")
    @ResponseBody
    public Map<String,Object>  selectstuAll(){
        Map<String,Object> map = new HashMap<>();
        map.put("result",true);
        return map;
    }
    /**
     * 一个班或所有学生男女比例
     * @return
     */
    @RequestMapping("radione")
    @ResponseBody
    public Map<String,Object> radione(Integer cid){
        Map<String,Object> studentMap = new HashMap<>();
        try{
            Clazz clazz = permissionService.ratio(cid);
            studentMap.put("result",true);
            studentMap.put("clazz",clazz);
        }
        catch (Exception e){
            studentMap.put("result",false);
        }
        return studentMap;
    }

    /**
     * 所有班男女比例
     * @return
     */
    @RequestMapping("radioAll")
    @ResponseBody
    public Map<String,Object> radioAll(){
        Map<String,Object> studentMap = new HashMap<>();
        try{
            List<Clazz> clazzList = permissionService.radioAll();
            studentMap.put("result",true);
            studentMap.put("clazzList",clazzList);
        }
        catch (Exception e){
            studentMap.put("result",false);
        }
        return studentMap;
    }

    /**
     * 所有班男女比例
     * @return
     */
    @RequestMapping("radioresourceDo")
    @ResponseBody
    public Map<String,Object> radioresourceDo(Integer cid){
        Map<String,Object> studentMap = new HashMap<>();
        try{
            List<ResourceVO> studentresourceList = permissionService.radioresource(cid);
            studentMap.put("result",true);
            studentMap.put("studentresourceList",studentresourceList);
        }
        catch (Exception e){
            studentMap.put("result",false);
        }
        return studentMap;
    }

    /**
     * 查询所有地区就业的工资 和人数
     * @return
     */
    @RequestMapping("salaryDo")
    @ResponseBody
    public Map<String,Object> salaryDo(Clazz clazz){
        Map<String,Object> studentMap = new HashMap<>();
        try{
            List<Job> jobList = permissionService.salary(clazz.getCid()+"",clazz.getBegin(),clazz.getEnd());
            studentMap.put("result",true);
            studentMap.put("jobList",jobList);
        }
        catch (Exception e){
            studentMap.put("result",false);
        }
        return studentMap;
    }
    /**
     * 展示已经毕业的学生
     */
    @RequestMapping("listDo")
    @ResponseBody
    public Map<String,Object> listDo(PageBean pageBean,Integer cid,String stname,String sid){
        Map<String,Object> studentMap = new HashMap<>();
        try{
            Map<String, Object> byConf = permissionService.findByConf(pageBean, cid, stname, sid);
            studentMap.put("result",true);
            studentMap.put("jobList",byConf.get("jobList"));
            studentMap.put("pageBean",pageBean);
        }
        catch (Exception e){
            studentMap.put("result",false);
        }
        return studentMap;
    }

    /**
     * 删除一个毕业生信息
     */
    @RequestMapping("deleteoneDo")
    @ResponseBody
    public Map<String,Object> deleteoneDo(Integer jid){
        Map<String,Object> studentMap = new HashMap<>();
        try{
            int parm = permissionService.deleteone(jid);
            studentMap.put("result",true);
        }
        catch (Exception e){
            studentMap.put("result",false);
        }
        return studentMap;
    }

    /**
     * 删除多个毕业生信息
     */
    @RequestMapping("deletemanyDo")
    @ResponseBody
    public Map<String,Object> deletemanyDo(Integer[] jid){
        Map<String,Object> studentMap = new HashMap<>();
        try{
            int parm = permissionService.deletemany(jid);
            if(parm>0)
                studentMap.put("result",true);
            else {
                studentMap.put("result",false);
            }
        }
        catch (Exception e){
            studentMap.put("result",false);
        }
        return studentMap;
    }
    /**
     * 新增一个毕业生信息
     */
    @RequestMapping("biyesaveDo")
    @ResponseBody
    public Map<String,Object> biyesaveDo(Integer cid,String sid,String salary,String loc){
        Map<String,Object> studentMap = new HashMap<>();
        try{
            int parm = permissionService.savebeyeInfo(cid,sid,salary,loc);
            if(parm>0)
                studentMap.put("result",true);
            else {
                studentMap.put("result",false);
            }
        }
        catch (Exception e){
            studentMap.put("result",false);
        }
        return studentMap;
    }

    /**
     * 修改一个毕业生信息(展示)
     */
    @RequestMapping("updateshowDo")
    @ResponseBody
    public Map<String,Object> updateshowDo(Integer jid){
        Map<String,Object> jobMap = new HashMap<>();
        try{
            Job job = permissionService.updateshow(jid);
            if(job != null) {
                jobMap.put("result", true);
                jobMap.put("job", job);
            }else {
                jobMap.put("result",false);
            }
        }
        catch (Exception e){
            jobMap.put("result",false);
        }
        return jobMap;
    }

    /**
     * 修改一个毕业生信息
     */
    @RequestMapping("updateDo")
    @ResponseBody
    public Map<String,Object> updateDo(Job job){
        Map<String,Object> studentMap = new HashMap<>();
        try{
            int parm = permissionService.updatebeyeInfo(job);
            if(parm>0)
                studentMap.put("result",true);
            else {
                studentMap.put("result",false);
            }
        }
        catch (Exception e){
            studentMap.put("result",false);
        }
        return studentMap;
    }

    /**
     * 查询所有角色
     * @param
     * @return
     */
    @RequestMapping("permissionDo")
    @ResponseBody
    public Map<String,Object> permissionDo() {
        Map<String, Object> map = new HashMap<>();
        try {
            List<Role> roleList = permissionService.findAll();
            map.put("roleList", roleList);
            map.put("result", true);
        } catch (Exception e) {
            map.put("result", false);
        }
        return map;
    }

    /**
     * 权限回填
     * @param
     * @return
     */
    @RequestMapping("showperDo")
    @ResponseBody
    public Map<String,Object> showperDo(String rid) {
        Map<String, Object> map = new HashMap<>();
        try {
            Map<String, Object> map2 = permissionService.find(rid);
            if (map2.size() > 0) {
                map.put("result", true);
                map.put("unassignperissionList", map2.get("unassignperissionList"));
                map.put("assignpermissionList", map2.get("assignpermissionList"));
                map.put("rid", Integer.parseInt(rid));
            } else {
                map.put("result", false);
            }
        }catch (Exception e){
            map.put("result",false);
        }
        return map;
    }

}
